﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using ZX.CRM.Bussiness;
using ZX.CRM.Library;
using ZX.EHR.Library;

namespace ZX.WebApp.Crm.Sale
{
    public partial class SaveTeachSumup : BasePage
    {
        BCrmTeachSumup Bbussness = new BCrmTeachSumup();  //业务处理类
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //itype
                string id = this.GetStringFromQueryString("ID", "");        //课程活动的主键 
                string TeachSumups = this.GetStringFromQueryString("TeachSumup", "");        //课程活动的主键 
                string type = this.GetStringFromQueryString("type", "");        //课程活动的主键 
                DatUser du = (DatUser)System.Web.HttpContext.Current.Session["User"]; //用户ID
                if (du == null)
                {
                    HttpContext.Current.Response.Write("当前用户信息出现异常！");
                    return;
                }
                if (TeachSumups.Split('︾').Length == 40)
                {
                    Bbussness.entity = new CrmTeachSumup();
                    V_CrmTeachSumup TeachSumup = new V_CrmTeachSumup();
                    
                    if (TeachSumups.Split('︾')[7].Trim().Length > 0)
                    {
                        TeachSumup.TutorId = new Guid(TeachSumups.Split('︾')[7]);
                    }
                   
                    if (TeachSumups.Split('︾')[35].Trim().Length > 100)
                    {
                        HttpContext.Current.Response.Write("成交原因字数不可以大于500！");
                        return;
                    }
                  
                    if (TeachSumups.Split('︾')[36].Trim().Length > 200)
                    {
                        HttpContext.Current.Response.Write("成交抗拒点字数不可以大于500！");
                        return;
                    }
                    
                    if (TeachSumups.Split('︾')[13].Trim().Length > 50)
                    {
                        HttpContext.Current.Response.Write("对客户的承诺字数不可以大于50！");
                        return;
                    }
                    
                    try
                    {
                        DateTime test = Convert.ToDateTime(TeachSumups.Split('︾')[9]);
                    }
                    catch
                    {
                        HttpContext.Current.Response.Write("预计上课时间请输入时间格式！");
                        return;
                    }
                    if (TeachSumups.Split('︾')[22].Trim().Length > 0)
                    {
                        try
                        {
                            DateTime test = Convert.ToDateTime(TeachSumups.Split('︾')[22]);
                        }
                        catch
                        {
                            HttpContext.Current.Response.Write("决策人生日请输入时间格式！");
                            return;
                        }
                    }
                    try
                    {
                        DateTime test = Convert.ToDateTime(TeachSumups.Split('︾')[27]);
                    }
                    catch
                    {
                        HttpContext.Current.Response.Write("成立日期请输入时间格式！");
                        return;
                    }
                    try
                    {
                        int   personsum = Convert.ToInt32(TeachSumups.Split('︾')[14]);
                    }
                    catch
                    {
                        HttpContext.Current.Response.Write("员工人数请输入整数格式！");
                        return;
                    }

                    try
                    {
                        float personsum = Convert.ToInt32(TeachSumups.Split('︾')[15]);
                    }
                    catch
                    {
                        HttpContext.Current.Response.Write("企业产值请输入数字格式！");
                        return;
                    }                   
                    try
                    {
                        int test = Convert.ToInt32(TeachSumups.Split('︾')[14]);
                    }
                    catch
                    {
                        HttpContext.Current.Response.Write("企业人数请输入数字！");
                        return;
                    }
                    try
                    {
                        int  test = Convert.ToInt32(TeachSumups.Split('︾')[38]);
                    }
                    catch
                    {
                        HttpContext.Current.Response.Write("成交家数必须是整数！");
                        return;
                    }
                    TeachSumup.IsGripe = TeachSumups.Split('︾')[0];
                    TeachSumup.IsClass = TeachSumups.Split('︾')[1];
                    TeachSumup.IsBargain = TeachSumups.Split('︾')[2];
                    TeachSumup.OrderId = new Guid(TeachSumups.Split('︾')[3]);
                    TeachSumup.ThodometerId = new Guid(id);
                    TeachSumup.IsStandard = TeachSumups.Split('︾')[4];
                    TeachSumup.JWXID = new Guid(TeachSumups.Split('︾')[5]);
                    TeachSumup.DeptId = new Guid(TeachSumups.Split('︾')[6]);
                    TeachSumup.GripeExplain = TeachSumups.Split('︾')[8];
                    TeachSumup.ClassExplain = TeachSumups.Split('︾')[9];
                    TeachSumup.Explain = TeachSumups.Split('︾')[10];
                    TeachSumup.PrelectDate = Convert.ToDateTime(TeachSumups.Split('︾')[11]);
                    TeachSumup.TeachPlace = TeachSumups.Split('︾')[12];
                    TeachSumup.CustomerPromis = TeachSumups.Split('︾')[13];
                    TeachSumup.Adduser = new Guid(du.UserID.ToString());
                    TeachSumup.Addtime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                    TeachSumup.PersonSum = Convert.ToInt32(TeachSumups.Split('︾')[14]);
                    TeachSumup.ProductSum = Convert.ToDecimal(TeachSumups.Split('︾')[15]);
                    TeachSumup.CompanyGain = TeachSumups.Split('︾')[16].ToString();
                    TeachSumup.TrainHistory = TeachSumups.Split('︾')[17].ToString();
                    TeachSumup.Painful = TeachSumups.Split('︾')[18].ToString();
                    TeachSumup.Pullulation = TeachSumups.Split('︾')[19].ToString();
                    TeachSumup.Homeplace=TeachSumups.Split('︾')[20].ToString();
                    TeachSumup.BirthdayType=TeachSumups.Split('︾')[21].ToString();
                    if (TeachSumups.Split('︾')[22].ToString().Trim().Length > 0)
                    {
                        TeachSumup.DecisionBirthday = Convert.ToDateTime(TeachSumups.Split('︾')[22].ToString());
                    }
                    else
                    {
                        TeachSumup.DecisionBirthday = Convert.ToDateTime("1900-1-1");
                    }
                    TeachSumup.Character = TeachSumups.Split('︾')[23].ToString();
                    TeachSumup.SchoolScientifc = TeachSumups.Split('︾')[24].ToString();
                    TeachSumup.DecisionFancy = TeachSumups.Split('︾')[25].ToString();
                    TeachSumup.Credit = TeachSumups.Split('︾')[26].ToString();
                    TeachSumup.CompanyCreateDate = Convert.ToDateTime(TeachSumups.Split('︾')[27].ToString());
                    TeachSumup.DecisionPersonsun = Convert.ToInt32(TeachSumups.Split('︾')[28].ToString());
                    TeachSumup.HighPersonsum = Convert.ToInt32(TeachSumups.Split('︾')[29].ToString());
                    TeachSumup.MiddlePersonsum = Convert.ToInt32(TeachSumups.Split('︾')[30].ToString());
                    TeachSumup.BelowPersonsum = Convert.ToInt32(TeachSumups.Split('︾')[31].ToString());
                    TeachSumup.TrainCompany = TeachSumups.Split('︾')[32].ToString();
                    if (TeachSumups.Split('︾')[33].ToString().Length == 0)
                    {
                        TeachSumup.TrainDate =Convert.ToDateTime("1901-1-1");
                    }
                    else
                    {
                        TeachSumup.TrainDate = Convert.ToDateTime(TeachSumups.Split('︾')[33].ToString());
                    }
                   
                    TeachSumup.CustomerPhylogeny = TeachSumups.Split('︾')[34].ToString();
                    TeachSumup.BargainReason = TeachSumups.Split('︾')[35].ToString();
                    TeachSumup.BargainDispute = TeachSumups.Split('︾')[36].ToString();
                    TeachSumup.AffectDecisioner = TeachSumups.Split('︾')[37].ToString();
                    TeachSumup.BargainNum  = Convert.ToInt32(TeachSumups.Split('︾')[38].ToString());
                    TeachSumup.IsValue = TeachSumups.Split('︾')[39];
                    if (type == "0")
                    {
                        TeachSumup.ID = Guid.NewGuid();
                        HttpContext.Current.Response.Write((Bbussness.ExecProc(TeachSumup, 0)));
                    }
                    else
                    {
                        if (this.GetStringFromQueryString("Teachsumupid", "").Trim().Length > 0)
                        {
                            TeachSumup.ID = new Guid(this.GetStringFromQueryString("Teachsumupid", ""));
                            HttpContext.Current.Response.Write((Bbussness.ExecProc(TeachSumup, 1)));

                        }
                    }
                }
            }
            catch
            {
                HttpContext.Current.Response.Write("数据异常！");
            }
        }
    }
}